package com.hsgene.message.service.impl;

import com.hsgene.common.util.basic.JsonUtils;
import com.hsgene.common.util.http.HttpConnectionManager;
import com.hsgene.message.domain.PushInfo;
import com.hsgene.message.service.NotificationPushService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 系统消息+极光推送service impl
 *
 * @author wxf
 * @date 2018/10/25 14:08
 **/
@Service
public class NotificationPushServiceImpl implements NotificationPushService {
    /**
     * Log
     */
    private final static Logger LOGGER = LogManager.getLogger(NotificationPushServiceImpl.class);

    @Resource
    private HttpConnectionManager httpConnectionManager;

    @Value("${jpush.url}")
    private String jpushUrl;

    /**
     * 系统消息+极光推送
     *
     * @param pushInfo 消息内容
     * @param userId   用户id
     * @param isPush   是否极光推送
     * @return
     */
    @Override
    public String pushNotification(PushInfo pushInfo, String userId, Boolean isPush) {
        String jsonStr = JsonUtils.objectToJson(pushInfo);
        String url = jpushUrl + "?userId=" + userId + "&isPush=" + isPush;
        return httpConnectionManager.doPost(jsonStr, url, "utf-8");
    }
}
